<!DOCTYPE html>
<html>
<head>
    {include file="layout:_meta" /}
</head>
<body>
<div class="layui-fluid" style="padding-top: 20px">
    <div class="layui-card">
        <div class="layui-card-header">七牛配置</div>
        <div class="layui-card-body">
            <form class="layui-form" lay-filter="layuiadmin-form-admin" action="{:url('config/qiniu')}">
                <div class="layui-tab layui-tab-brief" >
                    <ul class="layui-tab-title">
                        <li class="layui-this">七牛存储配置</li>
                    </ul>
                    <div class="layui-tab-content" >
                        <div class="layui-tab-item layui-show">
                            <div class="layui-form-item">
                                <label class="layui-form-label" style="width: 120px">是否开启：</label>
                                <div class="layui-input-block" style="margin-left: 150px">
                                    {if condition="!isset($list.open)||$list.open==true"}
                                    <input type="checkbox" lay-filter="open"  checked value="true" name="open" lay-skin="switch" lay-text="关闭|开启">
                                    {else /}
                                    <input type="checkbox" lay-filter="open"  value="true" name="open" lay-skin="switch" lay-text="关闭|开启">
                                    {/if}
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label" style="width: 120px">accessKey：</label>
                                <div class="layui-input-block" style="margin-left: 150px">
                                    <input type="text" name="accessKey" placeholder="请输入accessKey" autocomplete="off" class="layui-input" value="{:isset($list.accessKey)?$list.accessKey:''}">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label" style="width: 120px">secretKey：</label>
                                <div class="layui-input-block" style="margin-left: 150px">
                                    <input type="text" name="secretKey" placeholder="请输入secretKey" autocomplete="off" class="layui-input" value="{:isset($list.secretKey)?$list.secretKey:''}">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label" style="width: 120px">bucket空间：</label>
                                <div class="layui-input-block" style="margin-left: 150px">
                                    <input type="text" name="bucket" placeholder="请输入bucket空间" autocomplete="off" class="layui-input" value="{:isset($list.bucket)?$list.bucket:''}">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label" style="width: 120px">访问路径：</label>
                                <div class="layui-input-block" style="margin-left: 150px">
                                    <input type="text" name="uploadUrl" placeholder="请输入访问路径" autocomplete="off" class="layui-input" value="{:isset($list.uploadUrl)?$list.uploadUrl:''}">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit lay-filter="submit">确认</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

{include file="layout:_footer" /}
<script>
    var images = [];
    layui.config({
        base: '__static__/admin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'upload'], function(){
        var form = layui.form,$ = layui.$;

        form.on('switch(open)', function(data){
            this.value = this.checked?'true':'false';
            if (this.value=='false'){
                $('input[name="uploadUrl"]').val('');
                $('input[name="accessKey"]').val('');
                $('input[name="secretKey"]').val('');
                $('input[name="bucket"]').val('');
                $('input[name="uploadUrl"]').attr("disabled","disabled");
                $('input[name="accessKey"]').attr("disabled","disabled");
                $('input[name="secretKey"]').attr("disabled","disabled");
                $('input[name="bucket"]').attr("disabled","disabled");
            }else {
                $('input[name="accessKey"]').removeAttr("disabled");
                $('input[name="secretKey"]').removeAttr("disabled");
                $('input[name="bucket"]').removeAttr("disabled");
                $('input[name="uploadUrl"]').removeAttr("disabled");
                $('input[name="uploadUrl"]').val('');
            }
        });

        //监听表单提交
        form.on('submit(submit)', function(data){
            layer.confirm('您确认要提交吗？', {
                btn: ['确认','取消'] //按钮
            }, function(index){
                $.post(data.form.action, data.field, function (res) {
                    var icon = 5;
                    if (res.code) {
                        icon = 6;
                    }
                    layer.msg(res.msg, {icon: icon, time: 1500});
                }, 'json');
            }, function(){
                layer.msg('已取消..');
                return false;
            });
            return false;
        });
    })
</script>
</body>
</html>